package com.example.booklist.model;

import com.example.booklist.constant.UserConstant;
import com.example.booklist.enums.LoginEnum;
import jakarta.servlet.http.HttpSession;
import lombok.Data;

@Data
public class Result<T> {

    private LoginEnum code;
    private String message;
    private T data;

    public static<T> Result<T> unLogin() {
        Result<T> result = new Result<>();
        result.setMessage("用户未登录");
        result.setData(null);
        result.setCode(LoginEnum.UNLOGIN);
        return result;
    }

    public static<T> Result<T> success(T pageResult) {
        Result<T> result = new Result<>();
        result.setMessage("");
        result.setData(pageResult);
        result.setCode(LoginEnum.SUCCESS);
        return result;
    }

    public static<T> Result<T>fail() {
        Result<T> result = new Result<>();
        result.setMessage("用户登录失败");
        result.setData(null);
        result.setCode(LoginEnum.FAIL);
        return result;
    }

    public static<T> Result<T>fail(T message) {
        Result<T> result = new Result<>();
        result.setMessage("出现异常");
        result.setData(message);
        result.setCode(LoginEnum.FAIL);
        return result;
    }
}
